package cn.aib.educms.controller;


import cn.aib.commonutils.R;
import cn.aib.educms.entity.CrmBanner;
import cn.aib.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-01-13
 */
@RestController
@RequestMapping("/educms/banneradmin")
public class BannerAdminController {

    @Autowired
    private CrmBannerService crmBannerService;
    /**
     *  分页查询banner
     *  方法名：selectPageBanner
     *  参数：当前页，每页记录数
     *  返回值：R
     */
    @GetMapping("/cms/selectPageBanner/{current}/{limit}")
    public R selectPageBanner(@PathVariable Integer current,@PathVariable Integer limit){
        //创建page
        Page<CrmBanner> page = new Page<>(current, limit);

        //查询
        crmBannerService.page(page, null);

        //返回
        return R.ok().data("items",page.getRecords()).data("total",page.getTotal());
    }

    /**
     *  添加banner
     *  方法名：addBanner
     *  参数：CrmBanner banner
     *  返回值：R
     */
    @PostMapping("/cms/addBanner")
    public R addBanner(@RequestBody CrmBanner banner){

        //保存
        crmBannerService.saveBanner(banner);

        //返回
        return R.ok();
    }

    /**
     *  删除banner
     *  方法名：deleteBanner
     *  参数：Integer id
     *  返回值：R
     */
    @DeleteMapping("/cms/deleteBanner/{id}")
    public R deleteBanner(@PathVariable String id){

        //查询
        crmBannerService.removeBanner(id);

        //返回
        return R.ok();
    }
    /**
     *  修改banner
     *  方法名：updateBanner
     *  参数：CrmBanner banner
     *  返回值：R
     */
    @PostMapping("/cms/updateBanner")
    public R updateBanner(@RequestBody CrmBanner banner){
        //查询
        crmBannerService.updateBanner(banner);

        //返回
        return R.ok();
    }

}

